UiHelper.backdrop = UiHelper.frame:extend()
--- 创建backdrop
---@param frameId number
---@param relation number-相对节点ID(def:hdzui.origin.game())
---@param align number-integer-参考blizzard:^FRAME_ALIGN FRAME_ALIGN_CENTER
---@param alignRelation number以-align-> alignParent 对齐 FRAME_ALIGN_CENTER
---@param x number-锚点X
---@param y number-锚点Y
---@param fdfName string-frame名称
---@param parent number-父节点ID(def:hdzui.origin.game())
---@param tag string-自定义tag名称(def:cache.tagIdx)
---@param id number-integer(def:0)
---@param img string-("UI\\Widgets\\ToolTips\\Human\\human-tooltip-background.blp")
---@param w number-宽
---@param h number-高
---@param show bool-显示 隐藏
---animation{count=总帧数,path=图片位置}
function UiHelper.backdrop:new(args)
    args = args or {}
    args.fdfType = "BACKDROP"

    args.align = args.align or FRAME_ALIGN_CENTER
    args.alignRelation = args.alignRelation or FRAME_ALIGN_CENTER

    self.frame = UiHelper.frame(args)
    self.frameId = self.frame.frameId

    self.parent = args.parent

    self.img = args.img 
    self.relation = args.relation
    self.align = args.align
    self.alignRelation = args.alignRelation
    self.x = args.x
    self.y = args.y
    self.h = args.h
    self.w = args.w

    if self.img ~= nil then
        self:dfbackdrop(self)
    end

    if (args.animation ~= nil) then
        self.animation = args.animation
        self:backdropGif(self.animation.count, self.animation.path)
    end
    return self
end

---清空frame所有锚点
function UiHelper.backdrop:dfClearAllPoints()
    self.frame:dfClearAllPoints()
    return self
end
---backdrop图片路径
---@param img string 图片路径
function UiHelper.backdrop:dfbackdrop(img)
    self.frame:dfbackdrop(img)
    return self
end

---backdrop动态图片路径
---count 总帧数
---path 路径
function UiHelper.backdrop:backdropGif(count, path)
    if self.animation == nil then
        self.animation = {}
    end

    if self.backdropGifTime ~= nil then
        self.backdropGifTime.destroy()
    end

    self.animation.id = 0
    self.animation.count = count
    self.animation.path = path
    self.backdropGifTime =
        htime.setInterval(
        0.15,
        function(curTimer)
            if self.animation.id < self.animation.count then
                self.animation.id = self.animation.id + 1
            else
                self.animation.id = 1
            end

            self.img = self.animation.path .. tostring(self.animation.id) .. ".tga"
            self:dfbackdrop(self.img)
        end
    )
    return self
end

---设置宽高
function UiHelper.backdrop:dfsize(w, h)
    self.frame:dfsize(w, h)
    return self
end

---设置锚点 相对位置{point,relativeFrame,relativePoint}
function UiHelper.backdrop:dfpoint(x, y, point, relativeFrame, relativePoint)
    self.frame:dfpoint(x, y, point, relativeFrame, relativePoint)
    return self
end
---偏移
---@param relation number-相对节点ID(def:hdzui.origin.game())
---@param x number-锚点X
---@param y number-锚点Y
function UiHelper.backdrop:dfpointp(x, y, relation, align, alignRelation)
    self.frame:dfpointp(x, y, relation, align, alignRelation)
    return self
end

---设置绝对位置
function UiHelper.backdrop:dfAbsolutePoint(x, y, point)
    self.frame:dfAbsolutePoint(x, y, point)
    return self
end

---显示
function UiHelper.backdrop:dfshow(show)
    if show == nil then
        show = true
    end
    self.frame:dfshow(show)

    return self
end
---隐藏
function UiHelper.backdrop:dfhide()
    self.frame:dfhide()
    return self
end

---点击事件
function UiHelper.backdrop:CLICK(align)
    self.frame:CLICK(align)
    return self
end
---悬浮事件
function UiHelper.backdrop:ENTER(align)
    self.frame:ENTER(align)
    return self
end
---离开事件
function UiHelper.backdrop:LEAVE(align)
    self.frame:LEAVE(align)
    return self
end
---释放事件
function UiHelper.backdrop:RELEASE(align)
    self.frame:RELEASE(align)
    return self
end
--双击事件
function UiHelper.backdrop:DOUBLE_CLICK(align)
    self.frame:DOUBLE_CLICK(align)
    return self
end